#!/usr/anaconda/env python
# -*- coding: utf-8 -*-
# author: uestcwdh
# @Time: 2020/2/2 10:27
import streamlit as st
import pandas as pd

# # slider
# st.title("slider")
# x = st.slider("x")
# y = x ** 2
# y

st.title("crime events query app")


@st.cache
def load_data():
    df = pd.read_csv("csv/crime_data_20200110.csv")
    df.columns = ['crime_type', 'loc', 'datetime', 'public_address', 'agency', 'status']
    return df


df = load_data()
# display the first five columns
st.table(df.head())

crime_lst = df['crime_type'].unique()
crime_type = st.sidebar.selectbox(
    "Which kind of crime do you want to query?",
    crime_lst
)

loc_lst = df['loc'].unique()
loc = st.sidebar.selectbox(
    "Which location?",
    loc_lst
)


# query and format output
part_df = df[(df["crime_type"] == crime_type) & (df['loc'] == loc)]
st.write(f"根据你的筛选，数据包含{len(part_df)}行")
st.write("符合查询条件的结果如下:")
part_df

